//
//  Request.m
//  ChongDingTest
//
//  Created by luyee on 2020/9/2.
//  Copyright © 2020 luyee. All rights reserved.
//

#import "Request.h"
#import "HeapListModels.h"
#import <MJExtension.h>

@implementation Request

+ (void)request:(NSString *)urlStr withParams:(NSDictionary *)params success:(void (^)(Class model))success  {
    AFHTTPSessionManager *manager =[AFHTTPSessionManager manager];
    
    manager.responseSerializer = [[AFJSONResponseSerializer alloc] init];
    manager.responseSerializer.acceptableContentTypes =  [NSSet setWithObjects:@"application/json", @"text/plain", @"text/javascript", @"text/json", @"text/html",@"application/javascript" ,nil];
    
    [manager GET:urlStr parameters:params headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        // 这里的cls需要传过来，先写死
        Class cls = NSClassFromString(@"HeapListModel");
        id model = [cls mj_objectWithKeyValues:responseObject];
        success(model);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"请求失败 %@", task.currentRequest.URL);
        NSLog(@"%@", error);
    }];
}

@end
